package com.kkyy.msystem.interceptor;

import com.kkyy.msystem.entity.UsersEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

// 登录拦截器
@Component
public class SimpleAuthenticationInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        if (null == session.getAttribute(UsersEntity.SESSION_USER_KEY)) {
            request.getRequestDispatcher("/login").forward(request, response);
            return false;
        }
        return true;
    }
}